/* 
 * Copyright [2018] [Alex/libo(liboms@hotmail.com)]
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.schedule.executor.model;

import java.util.Date;

/** 
 * @title SimpleTriggerBean.java  
 * @package com.hyts.schedule.quartz.model  
 * @description TODO  
 * @see TODO
 * @author libo/Alex
 * @email liboms@hotmail.com/liboware@163.com  
 * @date 2018年5月18日 
 * @version V1.0 
 */
public class SimpleTriggerBean extends TriggerBean {

	/**  
	 * <p>是否永久循环</p> 
	 * @fieldName cycleForever
	 * @fieldType boolean
	 */ 
	private boolean cycleForever = Boolean.TRUE;
	
	/**  
	 * <p>{字段的描述}</p> 
	 * @fieldName startDate
	 * @fieldType Date
	 */ 
	private Date startDate;
	
	/**  
	 * <p>循环次数</p> 
	 * @fieldName repeatCount
	 * @fieldType Integer
	 */ 
	private Integer repeatCount;
	
	/**  
	 * <p>{字段的描述}</p> 
	 * @fieldName intervalPhase
	 * @fieldType Integer
	 */ 
	private Integer intervalPhase;
	
	/**  
	 * <p>{字段的描述}</p> 
	 * @fieldName unit
	 * @fieldType TriggerIntervalUnit
	 */ 
	private TriggerIntervalUnit unit;
	
	/**  
	 * @name cycleForever's getter method
	 * @param none
	 * @return cycleForever
	 */
	public boolean isCycleForever() {
		return cycleForever;
	}

	/**  
	 * @name cycleForever's setter method
	 * @param cycleForever
	 * @return void
	 */
	public void setCycleForever(boolean cycleForever) {
		this.cycleForever = cycleForever;
	}

	/**  
	 * @name startDate's getter method
	 * @param none
	 * @return startDate
	 */
	public Date getStartDate() {
		if(startDate == null ||
				startDate.getTime() < System.currentTimeMillis()){
			this.startDate = new Date();
		}
		return startDate;
	}

	/**  
	 * @name startDate's setter method
	 * @param startDate
	 * @return void
	 */
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	/**  
	 * @name repeatCount's getter method
	 * @param none
	 * @return repeatCount
	 */
	public Integer getRepeatCount() {
		return repeatCount;
	}

	/**  
	 * @name repeatCount's setter method
	 * @param repeatCount
	 * @return void
	 */
	public void setRepeatCount(Integer repeatCount) {
		this.repeatCount = repeatCount;
	}

	/**  
	 * @name intervalPhase's getter method
	 * @param none
	 * @return intervalPhase
	 */
	public Integer getIntervalPhase() {
		return intervalPhase;
	}

	/**  
	 * @name intervalPhase's setter method
	 * @param intervalPhase
	 * @return void
	 */
	public void setIntervalPhase(Integer intervalPhase) {
		this.intervalPhase = intervalPhase;
	}

	/**  
	 * @name unit's getter method
	 * @param none
	 * @return unit
	 */
	public TriggerIntervalUnit getUnit() {
		return unit;
	}

	/**  
	 * @name unit's setter method
	 * @param unit
	 * @return void
	 */
	public void setUnit(TriggerIntervalUnit unit) {
		this.unit = unit;
	}

	/**  
	 * @constructor：SimpleTriggerBean  
	 * @param triggerName
	 * @param triggerGroupName
	 * @param jobBean
	 * @param startDate
	 * @param repeatCount
	 * @param intervalPhase
	 * @param unit  
	 */ 
	public SimpleTriggerBean(String triggerName, String triggerGroupName,
			JobBean jobBean, Date startDate, Integer repeatCount,
			Integer intervalPhase, TriggerIntervalUnit unit) {
		super(triggerName, triggerGroupName, jobBean);
		this.startDate = startDate;
		this.cycleForever = Boolean.FALSE;
		this.repeatCount = repeatCount;
		this.intervalPhase = intervalPhase;
		this.unit = unit;
	}

	/**  
	 * @constructor：SimpleTriggerBean  
	 * @param triggerName
	 * @param triggerGroupName
	 * @param jobBean
	 * @param startDate
	 * @param intervalPhase
	 * @param unit  
	 */ 
	public SimpleTriggerBean(String triggerName, String triggerGroupName,
			JobBean jobBean, Date startDate,
			Integer intervalPhase, TriggerIntervalUnit unit) {
		super(triggerName, triggerGroupName, jobBean);
		this.startDate = startDate;
		this.intervalPhase = intervalPhase;
		this.unit = unit;
	}
	
	/** 
	 * @title SimpleTriggerBean.java  
	 * @package com.hyts.schedule.quartz.model  
	 * @description 支持的时间单位  
	 * @see TODO
	 * @author libo/Alex
	 * @email liboms@hotmail.com/liboware@163.com  
	 * @date 2018年5月19日 
	 * @version V1.0 
	 */  
	public enum TriggerIntervalUnit{
		DAYS,
		HOURS,
		MINUTES,
		SECONDS,
	}
}
